Deploy to AWS App Runner (with Upstash & Neon)
This guide explains how to deploy the Atom SaaS hybrid container (Next.js + Python) to AWS App Runner.
Architecture
- **Compute**: AWS App Runner (serverless container runner).
- **Database**: Neon (Postgres) or AWS RDS.
- **Cache/Rate Limits**: Upstash Redis (or AWS ElastiCache).
- **Container**: Single hybrid image exposing port
3000(Next.js) which proxies API calls tolocalhost:8000(Python).
---
1. Prerequisites
- AWS CLI installed and configured (
aws configure). - Docker installed.
- An existing ECR repository (or create one):
---
2. Build & Push Image
- **Authenticate Docker with ECR**:
- **Build the Image**:
- **Tag & Push**:
---
3. Configure Upstash Redis
Since App Runner instances are ephemeral and effectively serverless, **Upstash Redis** is the recommended serverless Redis solution if you want to avoid managing VPCs for ElastiCache.
- Create a database in the Upstash Console.
- Copy the **UPSTASH_REDIS_REST_URL** and **UPSTASH_REDIS_REST_TOKEN**.
- **IMPORTANT**: For Rate Limiting (
abuse-protection.ts), we use the standard Redis client (redisnpm package), so you need the **TCP connection string**, typicallyrediss://default:[password]@[endpoint]:[port].
---
4. Create App Runner Service
- Go to **AWS App Runner Console** > **Create service**.
- **Source**: Container registry > Amazon ECR.
- **Image URI**: Select the image you pushed (
atom-saas:latest). - **Deployment settings**: "Automatic" (redeploys on new push) or "Manual".
Configuration
- **Runtime**:
- **Port**:
3000(This is critical. Next.js runs on 3000). - **Environment variables**:
| Variable | Value | Description |
|---|---|---|
NODE_ENV | production | Optimization |
DATABASE_URL | postgresql://... | Connection to Neon or RDS |
REDIS_URL | rediss://... | Upstash TCP connection string |
NEXTAUTH_SECRET | [random-string] | For NextAuth.js |
NEXTAUTH_URL | https://[your-app-runner-url].awsapprunner.com | Update after creation |
JWT_SECRET | [random-string] | For API auth |
PYTHON_BACKEND_URL | http://localhost:8000 | **Default**, but explicit is safe |
- **Resources**:
- **CPU**: 1 vCPU (minimum).
- **Memory**: 2 GB (Recommended for hybrid stack).
---
5. Security & VPC (Optional)
If you decide to use **AWS RDS** and **ElastiCache** instead of Neon/Upstash:
- Create a **VPC Connector** in App Runner settings.
- Select the Subnets/Security Groups that have access to your RDS/ElastiCache instances.
---
6. Verify Deployment
- Wait for the service status to become **Running**.
- Visit the App Runner default domain.
- Test a Python API route (e.g.
GET /api/backend/health-> proxies tohttp://localhost:8000/api/health).
---
Troubleshooting
- **502 Bad Gateway**: App Runner health check failed. Ensure the container exposes port
3000and starts within the timeout. - **Python errors**: Check Application Logs in console. If
uvicornfails to start, theentrypoint.shtrap will kill the container.